home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWViews / Sources / FWContrH.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  21.6 KB  |  724 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWContrH.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifdef FW_BUILD_MAC
  11.  
  12. #include "FWFrameW.hpp"
  13.  
  14. #ifndef FWCONTRH_H
  15. #include "FWContrH.h"
  16. #endif
  17.  
  18. #ifndef FWSCLBAR_H
  19. #include "FWSclBar.h"
  20. #endif
  21.  
  22. #ifndef FWBUTTON_H
  23. #include "FWButton.h"
  24. #endif
  25.  
  26. #ifndef FWPOPUP_H
  27. #include "FWPopup.h"
  28. #endif
  29.  
  30. #ifndef FWFRAME_H
  31. #include "FWFrame.h"
  32. #endif
  33.  
  34. #ifndef FWWINDOW_H
  35. #include "FWWindow.h"
  36. #endif
  37.  
  38. #ifndef FWCONTXT_H
  39. #include "FWContxt.h"
  40. #endif
  41.  
  42. #ifndef FWITERS_H
  43. #include "FWIters.h"
  44. #endif
  45.  
  46. // ----- Foundation Layer -----
  47.  
  48. #ifndef FWNOTIFN_H
  49. #include "FWNotifn.h"
  50. #endif
  51.  
  52. #ifndef FWINTERE_H
  53. #include "FWIntere.h"
  54. #endif
  55.  
  56. #ifndef FWBNDSTR_H
  57. #include "FWBndStr.h"
  58. #endif
  59.  
  60. #ifndef FWCFMRES_H
  61. #include "FWCFMRes.h"
  62. #endif
  63.  
  64. // ----- OpenDoc Includes -----
  65.  
  66. #ifndef SOM_ODFacet_xh
  67. #include <Facet.xh>
  68. #endif
  69.  
  70. #ifndef SOM_ODCanvas_xh
  71. #include <Canvas.xh>
  72. #endif
  73.  
  74. #ifndef SOM_ODTransform_xh
  75. #include <Trnsform.xh>
  76. #endif
  77.  
  78. #ifndef SOM_ODShape_xh
  79. #include <Shape.xh>
  80. #endif
  81.  
  82. #if defined(__MWERKS__) && GENERATING68K
  83. // A hack to work around a bug
  84. #pragma import list somGetGlobalEnvironment
  85. #endif
  86.  
  87. //========================================================================================
  88. // Runtime Informations
  89. //========================================================================================
  90.  
  91. #ifdef FW_BUILD_MAC
  92. #pragma segment fwgadgts
  93. #endif
  94.  
  95. //FW_DEFINE_CLASS_M0(FW_CPrivMacControlHelper)
  96.  
  97. #define IS_POPUP_PROCID(id)  (id >= popupMenuProc && id <= popupMenuProc + popupUseWFont)
  98.  
  99. //========================================================================================
  100. // CLASS FW_CPrivMacControlHelper
  101. //========================================================================================
  102.  
  103. //----------------------------------------------------------------------------------------
  104. // FW_CPrivMacControlHelper::FW_CPrivMacControlHelper
  105. //----------------------------------------------------------------------------------------
  106.  
  107. FW_CPrivMacControlHelper::FW_CPrivMacControlHelper(Environment* ev, FW_CNativeControl* control,
  108.                                     short value, short min, short max, short procID,
  109.                                     const Str255 label, const FW_CFont& font, long refCon) :
  110.     fControl(control),
  111.     fControlHandle(NULL),
  112.     fControlMargin(0),
  113.     fMacProcId(procID),
  114.     fMacFontId(0),
  115.     fMacFontStyle(0),
  116.     fMacFontSize(12)
  117. {
  118.     Initialize(ev, value, min, max, label, font, refCon);
  119. }
  120.  
  121. //----------------------------------------------------------------------------------------
  122. // FW_CPrivMacControlHelper::~FW_CPrivMacControlHelper
  123. //----------------------------------------------------------------------------------------
  124.  
  125. FW_CPrivMacControlHelper::~FW_CPrivMacControlHelper()
  126. {
  127.     if (fControlHandle)
  128.         ::DisposeControl(fControlHandle);
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. // FW_CPrivMacControlHelper::Initialize
  133. //----------------------------------------------------------------------------------------
  134.  
  135. void FW_CPrivMacControlHelper::Initialize(Environment* ev, 
  136.                                         short value, 
  137.                                         short min,         // = menu ID for popups
  138.                                         short max,         // = titleWidth for popups
  139.                                         const Str255 label, 
  140.                                         const FW_CFont& font,
  141.                                         long refCon)
  142. {        
  143.     // Controls are created in the platform window
  144.     FW_CAcquiredODWindow aqODWindow = fControl->GetFrame(ev)->GetWindow(ev)->AcquireODWindow(ev);
  145.     GrafPtr    curWin = aqODWindow->GetPlatformWindow(ev);
  146.     
  147.     FW_CPlatformPoint qdLocation    = fControl->GetLocation(ev).AsPlatformPoint();
  148.     FW_CPlatformPoint qdSize        = fControl->GetSize(ev).AsPlatformPoint();
  149.  
  150.     FW_CPlatformRect rect(qdLocation.h, qdLocation.v,
  151.                           qdLocation.h + qdSize.h, qdLocation.v + qdSize.v);
  152.     
  153.     GrafPtr    oldPort;
  154.     GetPort(&oldPort);
  155.     SetPort(curWin);
  156.     
  157.     RgnHandle clipRgn = ::NewRgn();
  158.     if (clipRgn)
  159.     {
  160.         ::GetClip(clipRgn);
  161.         Rect emptyRect;
  162.         ::SetRect(&emptyRect, 0, 0, 0, 0);
  163.         ::ClipRect(&emptyRect);
  164.     }
  165.  
  166.     fMacFontId = font.MacGetFontID();
  167.     fMacFontStyle = font.MacGetFontStyle();
  168.     fMacFontSize = FW_FixedToInt(font.GetFontSize());
  169.     ::TextFont(fMacFontId);
  170.     ::TextFace(fMacFontStyle);
  171.     ::TextSize(fMacFontSize);
  172.     ::TextMode(srcOr);
  173.  
  174.     if (!font.IsEqual(FW_CFont(FW_kSystemFont12))) 
  175.     {
  176.         // Control uses its own font instead of the System Font
  177.         fMacProcId += kControlUsesOwningWindowsFontVariant;
  178.     }
  179.     
  180.     if (IS_POPUP_PROCID(fMacProcId) && max == 0 && label[0] > 0)
  181.     {
  182.         // Compute default title width
  183.         max = ::StringWidth(label) + 5;
  184.     }
  185.     
  186.     FW_CAcquireCFMResourceAccess* resAccess = OpenResFileForPopup(ev); 
  187.     
  188.     fControlHandle = ::NewControl(curWin, &rect, label, false, value, min, max, 
  189.                                                                     fMacProcId, refCon);
  190.     (**fControlHandle).contrlVis = 255;                         
  191.     ::SetControlReference(fControlHandle, (long) this);
  192.  
  193.     if (clipRgn)
  194.     {
  195.         ::SetClip(clipRgn);
  196.         ::DisposeRgn(clipRgn);
  197.     }
  198.  
  199.     if (oldPort != curWin) 
  200.         SetPort(oldPort);
  201.         
  202.     if (resAccess) 
  203.         delete resAccess;
  204. }
  205.  
  206. //----------------------------------------------------------------------------------------
  207. // FW_CPrivMacControlHelper::OpenResFileForPopup
  208. //----------------------------------------------------------------------------------------
  209. // OpenDoc bug or feature?  we must open the part's resource file before any call to
  210. // the control manager because the MENU resource of a popup won't be re-loaded correctly...
  211.  
  212. FW_CAcquireCFMResourceAccess* FW_CPrivMacControlHelper::OpenResFileForPopup(Environment* ev)
  213. {
  214.     FW_CAcquireCFMResourceAccess* resAccess = NULL;
  215.  
  216.     if (IS_POPUP_PROCID(fMacProcId)) 
  217.     {
  218.         resAccess = FW_NEW(FW_CAcquireCFMResourceAccess, (ev));
  219.         FW_ASSERT(resAccess);
  220.     }
  221.     return resAccess;
  222. }    
  223.     
  224. //----------------------------------------------------------------------------------------
  225. // FW_CPrivMacControlHelper::SetBounds
  226. //----------------------------------------------------------------------------------------
  227.  
  228. void FW_CPrivMacControlHelper::SetBounds(const FW_CPlatformRect& controlBounds)
  229. {
  230.     (*fControlHandle)->contrlRect = controlBounds;
  231. }
  232.  
  233. //----------------------------------------------------------------------------------------
  234. // FW_CPrivMacControlHelper::SetValue
  235. //----------------------------------------------------------------------------------------
  236.  
  237. void FW_CPrivMacControlHelper::SetValue(short value, const FW_CPlatformPoint& location,
  238.                                         const FW_CPlatformPoint& size)
  239. {
  240.     // If the value is the same as the current one it may be because we are updating
  241.     // the control in multiple facets (from FW_CNativeControl::PrivSetValue), so we need
  242.     // to force the redraw by changing the old value first
  243.     
  244.     if ((*fControlHandle)->contrlValue == value)
  245.         (*fControlHandle)->contrlValue = (value == 0) ? 1 : 0;
  246.         
  247.     SetupControl(location, size);
  248.     ::SetControlValue(fControlHandle, value);
  249. }
  250.  
  251. //----------------------------------------------------------------------------------------
  252. // FW_CPrivMacControlHelper::SetValue
  253. //----------------------------------------------------------------------------------------
  254.  
  255. void FW_CPrivMacControlHelper::SetValue(short value, FW_Boolean drawNow)
  256. {
  257.     if (drawNow)
  258.         ::SetControlValue(fControlHandle, value);
  259.     else
  260.         (*fControlHandle)->contrlValue = value;
  261. }
  262.  
  263. //----------------------------------------------------------------------------------------
  264. // FW_CPrivMacControlHelper::SetMin
  265. //----------------------------------------------------------------------------------------
  266.  
  267. void FW_CPrivMacControlHelper::SetMin(short min)
  268. {
  269.     // Turn off visibility to avoid unwanted drawing
  270.      short vis = (**fControlHandle).contrlVis;
  271.      (**fControlHandle).contrlVis = 0;
  272.      
  273.     ::SetControlMinimum(fControlHandle, min);
  274.     
  275.      (**fControlHandle).contrlVis = vis;
  276. }
  277.  
  278. //----------------------------------------------------------------------------------------
  279. // FW_CPrivMacControlHelper::SetMax
  280. //----------------------------------------------------------------------------------------
  281.  
  282. void FW_CPrivMacControlHelper::SetMax(short max)
  283. {
  284.     // Turn off visibility to avoid unwanted drawing
  285.      short vis = (**fControlHandle).contrlVis;
  286.      (**fControlHandle).contrlVis = 0;
  287.  
  288.     ::SetControlMaximum(fControlHandle, max);
  289.     
  290.      (**fControlHandle).contrlVis = vis;
  291. }
  292.  
  293. //----------------------------------------------------------------------------------------
  294. // FW_CPrivMacControlHelper::SetText
  295. //----------------------------------------------------------------------------------------
  296.  
  297. void FW_CPrivMacControlHelper::SetText(const FW_CString& text)
  298. {
  299.     Str255 pascalText;
  300.     text.ExportPascal(pascalText);
  301.  
  302.     // Turn off visibility to avoid unwanted drawing
  303.      short vis = (**fControlHandle).contrlVis;
  304.      (**fControlHandle).contrlVis = 0;
  305.  
  306.     ::SetControlTitle(fControlHandle, pascalText);
  307.  
  308.      (**fControlHandle).contrlVis = vis;
  309. }
  310.  
  311. //----------------------------------------------------------------------------------------
  312. // FW_CPrivMacControlHelper::GetText
  313. //----------------------------------------------------------------------------------------
  314.  
  315. void FW_CPrivMacControlHelper::GetText(FW_CString& text) const
  316. {
  317.     Str255 pascalText;
  318.     ::GetControlTitle(fControlHandle, pascalText);
  319.     text.ReplaceAll(pascalText);
  320. }
  321.  
  322. //----------------------------------------------------------------------------------------
  323. // FW_CPrivMacControlHelper::DrawControl
  324. //----------------------------------------------------------------------------------------
  325.  
  326. void FW_CPrivMacControlHelper::DrawControl(Environment* ev, ODFacet* facet)
  327. {
  328.     FW_CAcquiredODWindow aqODWindow = facet->GetFrame(ev)->AcquireWindow(ev);
  329.  
  330.     // All native Mac controls are drawn with Draw1Control except for
  331.     // inactive scroll-bars which are simply empty rectangles
  332.     if (fMacProcId != scrollBarProc || aqODWindow->IsActive(ev)) 
  333.     {
  334.         ::Draw1Control(fControlHandle);
  335.     }
  336.     else
  337.     {
  338.         // Use direct QD calls instead of ODF graphics because the control cannot
  339.         // scale anyway.
  340.         Rect sbRect = (*fControlHandle)->contrlRect;
  341.         ::FrameRect(&sbRect);
  342.         ::InsetRect(&sbRect, 1, 1);
  343.         ::EraseRect(&sbRect);
  344.     }
  345. }
  346.  
  347. //----------------------------------------------------------------------------------------
  348. // FW_CPrivMacControlHelper::Draw
  349. //----------------------------------------------------------------------------------------
  350.  
  351. void FW_CPrivMacControlHelper::Draw(Environment* ev,
  352.                                     ODFacet* facet, 
  353.                                     const FW_CPlatformPoint& location,
  354.                                     const FW_CPlatformPoint& size)
  355. {
  356.     FW_CAcquireCFMResourceAccess* resAccess = OpenResFileForPopup(ev); 
  357.     
  358.     if (facet->GetCanvas(ev)->IsDynamic(ev))
  359.     {
  360.         SetupControl(location, size);
  361.         DrawControl(ev, facet);
  362.      }
  363.      else
  364.      {
  365.          Print(ev, facet, location, size);
  366.      }
  367.      
  368.      if (resAccess)     delete resAccess;
  369. }
  370.  
  371. //----------------------------------------------------------------------------------------
  372. // FW_CPrivMacControlHelper::Print
  373. //----------------------------------------------------------------------------------------
  374.  
  375. void FW_CPrivMacControlHelper::Print(Environment* ev, ODFacet* facet, 
  376.                                     const FW_CPlatformPoint& location,
  377.                                     const FW_CPlatformPoint& size)
  378. {    
  379.     GrafPtr curPort;
  380.     ::GetPort(&curPort);
  381.     ::SetPort((**fControlHandle).contrlOwner);
  382.     SetupControl(FW_CPlatformPoint(0, 0), size);
  383.  
  384.     Rect srcRect;
  385.     srcRect.top = 0;
  386.     srcRect.left = 0;
  387.     srcRect.bottom = size.v;
  388.     srcRect.right = size.h;
  389.     
  390.     OpenCPicParams picParams;
  391.     picParams.srcRect = srcRect;
  392.     picParams.hRes = 0x00480000;
  393.     picParams.vRes = 0x00480000;
  394.     picParams.version = -2;
  395.     PicHandle picHandle = ::OpenCPicture(&picParams);
  396.     DrawControl(ev, facet);
  397.     ::ClosePicture();
  398.         
  399.      // ----- Set back the port and draw the picture -----
  400.      ::SetPort(curPort);
  401.      
  402.      ::OffsetRect(&srcRect, location.h, location.v);
  403.      ::DrawPicture(picHandle, &srcRect);
  404.      ::KillPicture(picHandle);
  405.  }
  406.  
  407. //----------------------------------------------------------------------------------------
  408. // FW_CPrivMacControlHelper::Enable
  409. //----------------------------------------------------------------------------------------
  410.  
  411. void FW_CPrivMacControlHelper::Enable(FW_Boolean enabled, const FW_CPlatformPoint& location,
  412.                                     const FW_CPlatformPoint& size)
  413. {
  414.     // Since we may be dealing with multiple facets we need to changing the old hilite 
  415.     // value first to force a correct redraw in each facet.
  416.     
  417.     short hilite = enabled ? 0 : 255;
  418.     
  419.     if (hilite == (*fControlHandle)->contrlHilite)
  420.         (*fControlHandle)->contrlHilite = 255 - hilite;
  421.  
  422.     SetupControl(location, size);
  423.     ::HiliteControl(fControlHandle, hilite); 
  424. }
  425.  
  426. //----------------------------------------------------------------------------------------
  427. // FW_CPrivMacControlHelper::Enable
  428. //----------------------------------------------------------------------------------------
  429.  
  430. void FW_CPrivMacControlHelper::Enable(FW_Boolean enabled)
  431. {
  432.     // Turn off visibility to avoid unwanted drawing
  433.      short vis = (**fControlHandle).contrlVis;
  434.      (**fControlHandle).contrlVis = 0;
  435.     
  436.     ::HiliteControl(fControlHandle, enabled ? 0 : 255);
  437.  
  438.      (**fControlHandle).contrlVis = vis;
  439. }
  440.  
  441. //----------------------------------------------------------------------------------------
  442. // FW_CPrivMacControlHelper::Show
  443. //----------------------------------------------------------------------------------------
  444. // This version of Show can be used for immediate drawing (like scrollbar activation)
  445.  
  446. void FW_CPrivMacControlHelper::Show(const FW_CPlatformPoint& location,
  447.                                     const FW_CPlatformPoint& size)
  448. {
  449.     // We need to reset the visibility to 0 before calling ::ShowControl to force the
  450.     // control manager to show it again. For instance a scrollbar activation may
  451.     // occur across multiple facets and this method will be called for each facet!
  452.      (**fControlHandle).contrlVis = 0;
  453.  
  454.     SetupControl(location, size);
  455.     ::ShowControl(fControlHandle);
  456. }
  457.  
  458. //----------------------------------------------------------------------------------------
  459. // FW_CPrivMacControlHelper::Show
  460. //----------------------------------------------------------------------------------------
  461.  
  462. void FW_CPrivMacControlHelper::Show()
  463. {
  464.     // Only change visibility flag.  View should be invalidated 
  465.      (**fControlHandle).contrlVis = 255;
  466. }
  467.  
  468. //----------------------------------------------------------------------------------------
  469. // FW_CPrivMacControlHelper::Hide
  470. //----------------------------------------------------------------------------------------
  471.  
  472. void FW_CPrivMacControlHelper::Hide()  
  473. {
  474.     // Only change visibility flag.  View should be invalidated 
  475.      (**fControlHandle).contrlVis = 0;
  476. }
  477.  
  478. //----------------------------------------------------------------------------------------
  479. // FW_CPrivMacControlHelper::Hide
  480. //----------------------------------------------------------------------------------------
  481.  
  482. void FW_CPrivMacControlHelper::SimulateButtonPressed(const FW_CPlatformPoint& location,
  483.                                     const FW_CPlatformPoint& size)
  484. {
  485.     SetupControl(location, size);
  486.     long ticks;
  487.     ::HiliteControl(fControlHandle, kControlButtonPart);
  488.     ::Delay(10, &ticks);
  489.     ::HiliteControl(fControlHandle, 0);
  490. }
  491.  
  492. //----------------------------------------------------------------------------------------
  493. // FW_CPrivMacControlHelper::MouseDown
  494. //----------------------------------------------------------------------------------------
  495.  
  496. FW_Boolean FW_CPrivMacControlHelper::MouseDown(Environment* ev, const FW_CViewContext& vc,
  497.                                                     const FW_CPlatformPoint& whereMouse)
  498. {
  499.     FW_CPlatformPoint controlLocation = vc.LogicalToDevice(FW_kZeroPoint);
  500.     FW_CPlatformPoint controlSize = GetControl()->GetSize(ev).AsPlatformPoint();
  501.  
  502.     SetupControl(controlLocation, controlSize);
  503.  
  504.     FW_CAcquireCFMResourceAccess* resAccess = OpenResFileForPopup(ev); 
  505.     
  506.     // [LSD] hack for popups who don't seem to respond to TestControl normally...
  507.     short partCode = ::TestControl(fControlHandle, whereMouse);
  508.     if (IS_POPUP_PROCID(fMacProcId))
  509.     {
  510.         partCode = kControlMenuPart;
  511.         ::PenSize(0, 0);
  512.         ::Draw1Control(fControlHandle);    
  513.         ::PenNormal();
  514.     }
  515.         
  516.     FW_Boolean mouseHandled = PartCodeSwitch(ev, vc, whereMouse, partCode);
  517.     
  518.     if (resAccess) 
  519.         delete resAccess;
  520.     
  521.     return mouseHandled;
  522. }
  523.  
  524. //----------------------------------------------------------------------------------------
  525. // FW_CPrivMacControlHelper::PartCodeSwitch
  526. //----------------------------------------------------------------------------------------
  527.  
  528. FW_Boolean FW_CPrivMacControlHelper::PartCodeSwitch(Environment* ev, const FW_CViewContext& vc, const FW_CPlatformPoint& whereMouse, short partCode)
  529. {
  530.     FW_Boolean mouseHandled = TRUE;
  531.     ODFacet* facet = vc.GetFacet();
  532.     
  533.     switch (partCode)
  534.     {    
  535.         case kControlButtonPart:
  536.         case kControlCheckBoxPart:  // = kControlRadioButtonPart: 
  537.             {
  538.                 if (::TrackControl(fControlHandle, whereMouse, NULL)) 
  539.                 {            
  540.                     GetControl()->ControlClicked(ev, GetValue(), facet);
  541.                 }
  542.             }    
  543.             break;
  544.             
  545.         case kControlIndicatorPart:
  546.         case kControlMenuPart:
  547.             {
  548.                 short before = GetValue();
  549.                 ::TrackControl(fControlHandle, whereMouse, (ControlActionUPP) (-1));
  550.                 short after = GetValue();
  551.                 
  552.                 if (after != before)
  553.                 {
  554.                     if (partCode == kControlIndicatorPart)
  555.                         after = after - before;    // use a delta for scroll bars
  556.                         
  557.                     GetControl()->ControlClicked(ev, after, facet);
  558.                 }
  559.                 
  560.             }
  561.             break;
  562.         
  563.         default:
  564.             mouseHandled = FALSE;
  565.     }
  566.     
  567.     return mouseHandled;
  568. }    
  569.  
  570. //----------------------------------------------------------------------------------------
  571. // FW_CPrivMacControlHelper::SetupControl
  572. //----------------------------------------------------------------------------------------
  573.  
  574. void FW_CPrivMacControlHelper::SetupControl(const FW_CPlatformPoint& location,
  575.                                          const FW_CPlatformPoint& size)
  576. {
  577.     // Set control coordinates
  578.     (*fControlHandle)->contrlRect.top = location.v + fControlMargin;
  579.     (*fControlHandle)->contrlRect.left = location.h + fControlMargin;
  580.     (*fControlHandle)->contrlRect.bottom = location.v + size.v - fControlMargin;
  581.     (*fControlHandle)->contrlRect.right = location.h + size.h - fControlMargin;
  582.     
  583.     ::PenNormal();
  584.  
  585.     // Set port's font if control doesn't use the default system font
  586.     if (fMacFontId != 0) 
  587.     {
  588.         ::TextFont(fMacFontId);
  589.         ::TextFace(fMacFontStyle);
  590.         ::TextSize(fMacFontSize);
  591.         ::TextMode(srcOr);    
  592.     }
  593. }
  594.  
  595. //========================================================================================
  596. //    CLASS FW_CPrivMacScrollBarControlHelper
  597. //========================================================================================
  598.  
  599. //----------------------------------------------------------------------------------------
  600. // FW_CPrivMacScrollBarControlHelper::FW_CPrivMacScrollBarControlHelper
  601. //----------------------------------------------------------------------------------------
  602.  
  603. FW_CPrivMacScrollBarControlHelper::FW_CPrivMacScrollBarControlHelper(Environment* ev, 
  604.                                                                     FW_CNativeControl* control,
  605.                                                                     short value, 
  606.                                                                     short min, 
  607.                                                                     short max,
  608.                                                                     long refCon) :
  609.     FW_CPrivMacControlHelper(ev, control, value, min, max, scrollBarProc, "\p", FW_kSystemFont12, refCon),
  610.     fFacet(0)
  611. {
  612. }
  613.  
  614. //----------------------------------------------------------------------------------------
  615. // FW_CPrivMacScrollBarControlHelper::~FW_CPrivMacScrollBarControlHelper
  616. //----------------------------------------------------------------------------------------
  617.  
  618. FW_CPrivMacScrollBarControlHelper::~FW_CPrivMacScrollBarControlHelper()
  619. {
  620. }
  621.  
  622. //----------------------------------------------------------------------------------------
  623. // FW_CPrivMacScrollBarControlHelper::PartCodeSwitch
  624. //----------------------------------------------------------------------------------------
  625.  
  626. FW_Boolean FW_CPrivMacScrollBarControlHelper::PartCodeSwitch(Environment* ev, 
  627.                                                             const FW_CViewContext& vc, 
  628.                                                             const FW_CPlatformPoint& whereMouse, 
  629.                                                             short partCode)
  630. {
  631.     FW_Boolean mouseHandled = FW_CPrivMacControlHelper::PartCodeSwitch(ev, vc, whereMouse, partCode);
  632.     
  633.     if (!mouseHandled)
  634.     {
  635.         mouseHandled = TRUE;
  636.         fFacet = vc.GetFacet();
  637.         
  638.         switch (partCode)
  639.         {    
  640.             case kControlDownButtonPart:
  641.             case kControlUpButtonPart:
  642.             case kControlPageDownPart:
  643.             case kControlPageUpPart:
  644.                 {
  645.                     ControlActionUPP actionProc = NewControlActionProc(&CallActionProc);
  646.                     
  647.                     ::TrackControl(fControlHandle, whereMouse, actionProc);
  648.                     DisposeRoutineDescriptor((UniversalProcPtr) actionProc);
  649.                 }
  650.                 break;
  651.                         
  652.             default:
  653.                 mouseHandled = FALSE;
  654.         }
  655.     }
  656.     
  657.     
  658.     return mouseHandled;
  659. }    
  660.  
  661. //----------------------------------------------------------------------------------------
  662. // FW_CPrivMacScrollBarControlHelper::CallActionProc
  663. //----------------------------------------------------------------------------------------
  664.  
  665. pascal void FW_CPrivMacScrollBarControlHelper::CallActionProc(ControlHandle controlHandle,
  666.                                                   short partCode)
  667. {
  668.     FW_CPrivMacScrollBarControlHelper *controlHelper = (FW_CPrivMacScrollBarControlHelper *) ::GetControlReference(controlHandle);
  669.     
  670.     controlHelper->ActionProc(partCode);
  671. }
  672.  
  673. //----------------------------------------------------------------------------------------
  674. // FW_CPrivMacScrollBarControlHelper::ActionProc
  675. //----------------------------------------------------------------------------------------
  676.  
  677. void FW_CPrivMacScrollBarControlHelper::ActionProc(short partCode)
  678. {
  679.     Environment *ev = somGetGlobalEnvironment();
  680.     
  681.     FW_CScrollBar* scrollBar = FW_DYNAMIC_CAST(FW_CScrollBar, GetControl());
  682.     FW_ASSERT(scrollBar);
  683.     FW_ASSERT(fFacet);
  684.  
  685.     FW_Fixed changeBy = FW_kFixed0;
  686.     
  687.     switch (partCode)
  688.     {
  689.         case kControlDownButtonPart:
  690.             changeBy = scrollBar->GetMinorScrollUnits(ev);
  691.             break;
  692.             
  693.         case kControlUpButtonPart:
  694.             changeBy = -scrollBar->GetMinorScrollUnits(ev);
  695.             break;
  696.             
  697.         case kControlPageDownPart:
  698.             changeBy = scrollBar->GetMajorScrollUnits(ev);
  699.             break;
  700.             
  701.         case kControlPageUpPart:
  702.             changeBy = -scrollBar->GetMajorScrollUnits(ev);
  703.             break;
  704.     };
  705.  
  706.     short before = GetValue();
  707.     short after = before + FW_FixedToInt(changeBy);
  708.     
  709.     short min = GetMin();
  710.     short max = GetMax();
  711.     if (after < min)
  712.         after = min;
  713.     else if (after > max)
  714.         after = max;
  715.  
  716.     if (after != before)
  717.     {        
  718.         GetControl()->ControlClicked(ev, after - before, fFacet);
  719.     }
  720. }
  721.  
  722.  
  723. #endif
  724.